﻿using System;
using WSKnowledge.WSHelpers.DesignByContract;
using MbUnit.Framework;

namespace WSKnowledge.WSHelpers.Tests
{
	public class HashingFixture
	{
		[Test]
		[Row("1!2@3#45$6")]
		[Row("1 ! 2 @ 3 # 4 5 $ 6 ;")]
		[Row("A string of any tokenSize and any content")]
		public void CanHashString(string input)
		{
			string hashed = Hashing.GetHash(input);
			Console.WriteLine("Test Value: [{0}] Hashed Value: [{1}]", input, hashed);
			Console.WriteLine("Hashed value length is {0}", hashed.Length);
			Assert.AreNotEqual(input, hashed);
			Assert.IsTrue(hashed.IsNotEmpty());
			Assert.IsTrue(hashed.IsExactly(32));
		}

		[Test]
		public void CannotHashEmptyString()
		{
			string testString = "";
			Assert.Throws<PreconditionException>(() => Hashing.GetHash(testString));
		}

		[Test]
		public void CannotHashNull()
		{
			string testString = null;
			Assert.Throws<PreconditionException>(() => Hashing.GetHash(testString));
		}

		[Test]
		[Row(13)]
		[Row(200)]
		[Row(70)]
		[Row(512)]
		[Row(32)]
		public void CanGenerateRandomString(int size)
		{
			string generated = Hashing.GenerateToken(size);
			Assert.IsTrue(generated.IsExactly(size));	
		}
	}
}
